local skel = fk.CreateSkill{
  name = "sj_zhoushuhuizhan__jingtingquan",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["sj_zhoushuhuizhan__jingtingquan"] = "迳庭拳",
  [":sj_zhoushuhuizhan__jingtingquan"] = "<b>锁定技</b>，你视为拥有交换技能描述中的【杀】与【闪】的〖<a href=':sj_zhoushuhuizhan__jingtingquan_juesi'>决死</a>〗与〖<a href=':sj_zhoushuhuizhan__jingtingquan_leiji'>雷击</a>〗。",
  [":sj_zhoushuhuizhan__jingtingquan_leiji"] = "当你使用或打出【杀】后，你可以令一名其他角色进行一次判定，若结果为：♠，你对其造成2点雷电伤害；♣，你回复1点体力，"..
  "对其造成1点雷电伤害。",
  [":sj_zhoushuhuizhan__jingtingquan_juesi"] = "出牌阶段，你可以弃置一张【闪】并选择攻击范围内的一名其他角色，然后令该角色弃置一张牌。若该角色弃置的牌不为【闪】且"..
  "其体力值不小于你，你视为对其使用一张【决斗】。",

  ["#sj_zhoushuhuizhan__jingtingquan_juesi"] = "决死：弃置一张【闪】，令一名角色弃一张牌",
  ["#sj_zhoushuhuizhan__jingtingquan_juesi-discard"] = "决死：你需弃置一张牌，若不为【闪】且你体力值不小于 %src，视为其对你使用【决斗】",

  ["#sj_zhoushuhuizhan__jingtingquan-choose"] = "雷击：令一名角色进行判定，若为♠，你对其造成2点雷电伤害；若为♣，你回复1点体力，对其造成1点雷电伤害",

  ["$sj_zhoushuhuizhan__jingtingquan1"] = "",
  ["$sj_zhoushuhuizhan__jingtingquan2"] = "",
}

local leiji_spec = {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.card.trueName == "slash"
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room.alive_players,
      skill_name = skel.name,
      prompt = "#sj_zhoushuhuizhan__jingtingquan-choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local judge = {
      who = to,
      reason = skel.name,
      pattern = ".|.|spade,club",
    }
    room:judge(judge)
    if judge.card.suit == Card.Spade then
      if not to.dead then
        room:damage{
          from = player,
          to = to,
          damage = 2,
          damageType = fk.ThunderDamage,
          skillName = skel.name,
        }
      end
    elseif judge.card.suit == Card.Club then
      if player:isWounded() and not player.dead then
        room:recover{
          who = player,
          num = 1,
          recoverBy = player,
          skillName = skel.name,
        }
      end
      if not to.dead then
        room:damage{
          from = player,
          to = to,
          damage = 1,
          damageType = fk.ThunderDamage,
          skillName = skel.name,
        }
      end
    end
  end,
}

skel:addEffect("active", {
  anim_type = "offensive",
  prompt = "#sj_zhoushuhuizhan__jingtingquan_juesi",
  card_num = 1,
  target_num = 1,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).trueName == "jink" and not player:prohibitDiscard(to_select)
  end,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and not to_select:isNude() and player:inMyAttackRange(to_select)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:throwCard(effect.cards, skel.name, player, player)
    if target.dead then return end
    local card = room:askToDiscard(target, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      skill_name = skel.name,
      prompt = "#sj_zhoushuhuizhan__jingtingquan_juesi-discard:"..player.id,
      cancelable = false,
      skip = true,
    })
    if #card > 0 then
      card = Fk:getCardById(card[1])
      room:throwCard(card, skel.name, target, target)
      if card.trueName ~= "jink" and target.hp >= player.hp and
        not player.dead and not target.dead then
        room:useVirtualCard("duel", nil, player, target, skel.name)
      end
    end
  end,
})


skel:addEffect(fk.CardUsing, leiji_spec)
skel:addEffect(fk.CardResponding, leiji_spec)

return skel
